<?php

use app\core\db\UuidTypeTrait;
use yii\db\Migration;

/**
 * Handles the creation of table `{{%users}}`.
 */
class m220621_151741_create_users_table extends Migration
{
    use UuidTypeTrait;

    /**
     * {@inheritdoc}
     * @throws \yii\base\Exception
     */
    public function safeUp(): void
    {
        $this->createTable('{{%users}}', [
            'id' => $this->uuid(),
            'username' => $this->string(191),
            'auth_key' => $this->string(32)->notNull(),
            'password_hash' => $this->string(191)->notNull(),
            'password_reset_token' => $this->string(191)->unique(),
            'email' => $this->string(191)->notNull()->unique(),
            'email_confirm_token' => $this->string(191)->unique(),
            'user_pic' => $this->string(191),
            'status' => $this->smallInteger()->notNull()->defaultValue(10),
            'factor2_use' => $this->integer(1)->defaultValue(0),
            'factor2_code' => $this->string(16),
            'settings' => $this->json()->null(),
            'allowance' => $this->integer(),
            'allowance_updated_at' => $this->integer()->unsigned(),
            'created_at' => $this->integer()->unsigned()->notNull(),
            'updated_at' => $this->integer()->unsigned()->notNull(),
        ]);

        $this->addPrimaryKey('pk-users', '{{%users}}', 'id');
    }

    /**
     * {@inheritdoc}
     */
    public function safeDown(): void
    {
        $this->dropTable('{{%users}}');
    }
}
